package com.shop.utils;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @date 2021/12/21 - 19:51
 */

@Component
public class MyIntercept implements HandlerInterceptor{

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//
//        String uri = request.getRequestURI();
//        if (uri.equals("/") || uri.equals("/login") || uri.equals("/doLogin")){
//            return true;
//        }

        Object user = request.getSession().getAttribute("user");


        if (user != null){
            System.out.println("-------------------成功跳转");
            return true;
        }
        System.out.println(request.getRequestURI());
        System.out.println("-------------------到登录去");
        response.sendRedirect("/");


        return false;
    }
}
